package com.data.controller.report;

import com.data.Const;
import com.data.controller.BaseController;
import com.data.domain.manage.*;
import com.data.domain.report.Systeminfo;
import com.data.domain.statistics.Orgnetinfo;
import com.data.josonbean.auth.Auth;
import com.data.model.ManagerModel;
import com.data.model.ReportModel;
import com.data.model.StatisticsModel;
import com.data.model.SystemModel;
import com.data.service.manage.*;
import com.data.service.system.AreainfoService;
import com.data.utill.*;
import jdk.internal.org.objectweb.asm.tree.analysis.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.net.ssl.HttpsURLConnection;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.*;

/**
 * Created by silenceholic on 2017/5/8.
 */
@Controller
@RequestMapping("manage/")
public class ManageController extends BaseController{

    @Resource(name = "riskcheckService")
    private RiskcheckService riskcheckService;

    @Resource(name = "orgroundinfoService")
    private OrgroundinfoService orgroundinfoService;

    @Resource(name="orginfoService")
    private OrginfoService orginfoService;

    @Resource(name="orgaccountService")
    private OrgaccountService orgaccountService;

    @Resource(name="orgauthService")
    private OrgauthService orgauthService;

    @Resource(name = "netroundinfoService")
    private NetroundinfoService netroundinfoService;

    @Resource(name = "consigninfoService")
    private ConsigninfoService consigninfoService;

    @Resource(name = "acctbindinfoService")
    private AcctbindinfoService acctbindinfoService;

    @Resource(name = "areainfoService")
    private AreainfoService areainfoService;

    @Resource(name = "acctbindlistService")
    private AcctbindlistService acctbindlistService;


    /**
     * 机构风险检查表基本查询
     * @return
     */

    @ResponseBody
    @RequestMapping(value = "riskcheck.htm" )
    public ModelAndView getRiskcheck(@ModelAttribute ManagerModel managerModel,HttpSession session){
        Map<String, Object> map = new HashMap<String, Object>();
        String areacode = ((Auth)session.getAttribute(Const.SESSION_USER)).getUser().getAreacode();
        managerModel.setOrgcodelist(orginfoService.getOrgcodeByAreacode(areacode));
        managerModel.setAreacode(areacode);
        List<Riskcheck> data = riskcheckService.getRiskcheck(managerModel);
        map.put("data",data);
        map.put("recordsTotal", data.size());
        map.put("recordsFiltered", data.size());
        map.put("orgcode",managerModel.getOrgcode());
        map.put("prtry",managerModel.getPrtry());
        ModelAndView mv = super.modelAndView(map);
        mv.setViewName("manage/riskcheck");
        return mv;

    }

    @ResponseBody
    @RequestMapping(value = "orgroundinfo.htm" )
    public ModelAndView getOrgroundinfo(@ModelAttribute ManagerModel managerModel,HttpSession session){
        Map<String, Object> map = new HashMap<String, Object>();
        String areacode = ((Auth)session.getAttribute(Const.SESSION_USER)).getUser().getAreacode();
        managerModel.setOrgcodelist(orginfoService.getOrgcodeByAreacode(areacode));
        managerModel.setAreacode(areacode);
        List<Orgroundinfo> data = orgroundinfoService.getOrgroundinfo( managerModel);
        map.put("data",data);
        map.put("recordsTotal", data.size());
        map.put("recordsFiltered", data.size());
        map.put("orgcode", managerModel.getOrgcode());
        map.put("trncode", managerModel.getTrncode());
        ModelAndView mv = super.modelAndView(map);
        mv.setViewName("manage/orgroundinfo");
        return mv;
    }


    @ResponseBody
    @RequestMapping(value = "orginfo.htm" )
    public ModelAndView getOrginfo(@ModelAttribute ManagerModel managerModel,HttpSession session){
        Map<String, Object> map = new HashMap<String, Object>();
        String areacode = ((Auth)session.getAttribute(Const.SESSION_USER)).getUser().getAreacode();
        managerModel.setAreacode(areacode);
        List<Orginfo> data = orginfoService.getOrginfo(managerModel);
        map.put("orgtypes",CommonOption.getOrgtypeOption());
        map.put("busiallows",CommonOption.getBusiallowOption());
        map.put("consigntypes",CommonOption.getConsigntypeOption());
        map.put("checkflags",CommonOption.getCheckflagOption());
        map.put("mactypes",CommonOption.getMactypeOption());
        map.put("nodetypes",CommonOption.getNodetypeOption());
        map.put("svctypes",CommonOption.getSvctypeOption());
        map.put("commtypes",CommonOption.getCommtypeOption());
        map.put("orgstats",CommonOption.getOrgstatOption());
        map.put("downmodes",CommonOption.getDownmodeOption());
        map.put("data",data);
        map.put("recordsTotal", data.size());
        map.put("recordsFiltered", data.size());
        map.put("start",managerModel.getStart());
        map.put("end",managerModel.getEnd());
        map.put("code",managerModel.getCode());
        ModelAndView mv = super.modelAndView(map);
        mv.setViewName("manage/orginfo");
        return mv;
    }

    /**
     *入网机构账户信息表基本查询
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "orgaccount.htm" )
    public ModelAndView getOrgaccount(@ModelAttribute ManagerModel managerModel,HttpSession session){
        Map<String, Object> map = new HashMap<String, Object>();
        String areacode = ((Auth)session.getAttribute(Const.SESSION_USER)).getUser().getAreacode();
        managerModel.setOrgcodelist(orginfoService.getOrgcodeByAreacode(areacode));
        managerModel.setAreacode(areacode);
        List<Orgaccount> data = orgaccountService.getOrgaccount(managerModel);
        map.put("data",data);
        map.put("recordsTotal", data.size());
        map.put("states",CommonOption.getorgAccountStateOption());
        map.put("bookmodes",CommonOption.getBookmodeOption());
        map.put("recordsFiltered", data.size());
        map.put("orgcode",managerModel.getOrgcode());
        map.put("state",managerModel.getState());
        ModelAndView mv = super.modelAndView(map);
        mv.setViewName("manage/orgaccount");
        return mv;
    }

    /**
     *机构业务权限限制表基本查询
     * @return
     */
//    @RequestMapping(value = "orgauth.htm")
//    public String allOrgauth(){
//        return "manage/orgauth";
//    }

    @ResponseBody
    @RequestMapping(value = "orgauth.htm" )
    public ModelAndView getOrgauth(@ModelAttribute ManagerModel managerModel){
        Map<String, Object> map = new HashMap<String, Object>();
        List<Orgauth> data = orgauthService.getOrgauth(managerModel);
        map.put("data",data);
        map.put("recordsTotal", data.size());
        map.put("recordsFiltered", data.size());
        map.put("sender",managerModel.getSender());
        map.put("recver",managerModel.getRecver());
        ModelAndView mv = super.modelAndView(map);
        mv.setViewName("manage/orgauth");
        return mv;
    }

    /**
     *轧差场次信息表基本查询
     * @return
     */

    @ResponseBody
    @RequestMapping(value = "netroundinfo.htm" )
    public ModelAndView getNetroundinfo(@ModelAttribute ManagerModel managerModel){
        Map<String, Object> map = new HashMap<String, Object>();
        List<Netroundinfo> data = netroundinfoService.getNetroundinfo(managerModel);
        map.put("data",data);
        map.put("recordsTotal", data.size());
        map.put("recordsFiltered", data.size());
        map.put("netround", managerModel.getNetround());
        ModelAndView mv = super.modelAndView(map);
        mv.setViewName("manage/netroundinfo");
        return mv;

    }

    /**
     *协议授权信息表基本查询
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "consigninfo.htm" )
    public ModelAndView getConsigninfo(@ModelAttribute ManagerModel managerModel,HttpSession session){
        Map<String, Object> map = new HashMap<String, Object>();
        String areacode = ((Auth)session.getAttribute(Const.SESSION_USER)).getUser().getAreacode();
        managerModel.setOrgcodelist(orginfoService.getOrgcodeByAreacode(areacode));
        managerModel.setAreacode(areacode);
        List<Consigninfo> data = consigninfoService.getConsigninfo(managerModel);
        map.put("data",data);
        map.put("recordsTotal", data.size());
        map.put("recordsFiltered", data.size());
        map.put("orgcode", managerModel.getOrgcode());
        map.put("consignnumb", managerModel.getConsignnumb());
        map.put("state", managerModel.getState());
        ModelAndView mv = super.modelAndView(map);
        mv.setViewName("manage/consigninfo");
        return mv;

    }

    /**
     * 账户绑定信息表基本查询
     * @return
     */

    @ResponseBody
    @RequestMapping(value = "acctbindinfo.htm" )
    public ModelAndView getAcctbindinfo(@ModelAttribute ManagerModel managerModel,HttpSession session){
        Map<String, Object> map = new HashMap<String, Object>();
        String areacode = ((Auth)session.getAttribute(Const.SESSION_USER)).getUser().getAreacode();
        managerModel.setOrgcodelist(orginfoService.getOrgcodeByAreacode(areacode));
        managerModel.setAreacode(areacode);
        List<Acctbindinfo> data = acctbindinfoService.getAcctbindinfo(managerModel);
        map.put("data",data);
        map.put("recordsTotal", data.size());
        map.put("recordsFiltered", data.size());
        map.put("orgcode", managerModel.getOrgcode());
        map.put("consignnumb", managerModel.getConsignnumb());
        map.put("state", managerModel.getState());
        map.put("dbtrclass",CommonOption.getCdtrclassOption());
        ModelAndView mv = super.modelAndView(map);
        mv.setViewName("manage/acctbindinfo");
        return mv;

    }

    /**
     * 账户绑定流水表
     * @param managerModel
     * @param session
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "acctbindlist.htm" )
    public ModelAndView getacctbindlist(@ModelAttribute ManagerModel managerModel,HttpSession session){
        Map<String, Object> map = new HashMap<String, Object>();
        String areacode = ((Auth)session.getAttribute(Const.SESSION_USER)).getUser().getAreacode();
        managerModel.setOrgcodelist(orginfoService.getOrgcodeByAreacode(areacode));
        managerModel.setAreacode(areacode);
        List<Acctbindlist> data = acctbindlistService.getAcctbindlist(managerModel);
        map.put("data",data);
        map.put("recordsTotal", data.size());
        map.put("recordsFiltered", data.size());
//        map.put("orgcode", managerModel.getOrgcode());
//        map.put("consignnumb", managerModel.getConsignnumb());
//        map.put("state", managerModel.getState());
        ModelAndView mv = super.modelAndView(map);
        mv.setViewName("manage/acctbindlist");
        return mv;

    }
    /******************************************************增加和修改**************************************************/
    /**
     * 插入入网机构信息表
     * @param managerModel
     * @return
     */
    @RequestMapping(value = "insert/orginfo.do" ,method = RequestMethod.POST)
    public Object insertOrginfo(@ModelAttribute ManagerModel managerModel, HttpSession session){
        String areacode = ((Auth)session.getAttribute(Const.SESSION_USER)).getUser().getAreacode();
        managerModel.setAreacode(areacode);
        if (orginfoService.insertOrginfo(managerModel)==1) {
            return "redirect:" + Const.CONTROLLER_MANAGE_ORGINFO;
        }else{
            return "redirect:" + Const.CONTROLLER_MANAGE_ORGINFO;//先这样写，错误页面需要再做到时候跳转错误提示
        }
    }
    /**
     * 跳转到修改入网机构信息表
     * @param
     * @return
     **/
    @RequestMapping(value = "modify/orginfo.htm" )
    public ModelAndView modifyOrginfoDispatch(@RequestParam(value = "id", required = false) String id){
        Map<String, Object> map = new HashMap<String, Object>();
        Orginfo data = orginfoService.getOrginfoById(Integer.parseInt(id));
        map.put("orgtypes",CommonOption.getOrgtypeOption());
        map.put("busiallows",CommonOption.getBusiallowOption());
        map.put("consigntypes",CommonOption.getConsigntypeOption());
        map.put("checkflags",CommonOption.getCheckflagOption());
        map.put("mactypes",CommonOption.getMactypeOption());
        map.put("nodetypes",CommonOption.getNodetypeOption());
        map.put("svctypes",CommonOption.getSvctypeOption());
        map.put("commtypes",CommonOption.getCommtypeOption());
        map.put("orgstats",CommonOption.getOrgstatOption());
        map.put("downmodes",CommonOption.getDownmodeOption());
        map.put("item",data);
        ModelAndView mv = super.modelAndView(map);
        mv.setViewName("manage/modifyorginfo");
        return mv;
    }

    /**
     * 修改入网机构信息表
     * @param
     * @return
     */
    @RequestMapping(value = "modify/orginfo.do" ,method = RequestMethod.POST)
    public Object modifyOrginfo(@ModelAttribute ManagerModel managerModel,
                                @RequestParam(value = "id", required = false) String id){
        orginfoService.modifyOrginfo(managerModel,Integer.parseInt(id));
        return "redirect:" + Const.CONTROLLER_MANAGE_ORGINFO;

    }

    /**
     * 插入入网机构账户
     * @param managerModel
     * @return
     */
    @RequestMapping(value = "insert/orgaccount.do" ,method = RequestMethod.POST)
    public Object insertOrgaccount(@ModelAttribute ManagerModel managerModel){

        if (orgaccountService.insertOrgaccount(managerModel)==1) {
            return "redirect:" + Const.CONTROLLER_MANAGE_ORGACCOUNT;
        }else{
            return "redirect:" + Const.CONTROLLER_MANAGE_ORGACCOUNT;//先这样写，错误页面需要再做到时候跳转错误提示
        }
    }
    /**
     * 跳转到修改入网机构账户
     * @param
     * @return
     **/
    @RequestMapping(value = "modify/orgaccount.htm" )
    public ModelAndView modifyOrgAccountDispatch(@RequestParam(value = "id", required = false) String id){
        Map<String, Object> map = new HashMap<String, Object>();
        Orgaccount data = orgaccountService.getOrgaccountById(Integer.parseInt(id));
        map.put("item",data);
        map.put("states",CommonOption.getorgAccountStateOption());
        map.put("bookmodes",CommonOption.getBookmodeOption());
        ModelAndView mv = super.modelAndView(map);
        mv.setViewName("manage/modifyorgaccount");
        return mv;
    }

    /**
     * 修改入网机构账户
     * @param
     * @return
     */
    @RequestMapping(value = "modify/orgaccount.do" ,method = RequestMethod.POST)
    public Object modifyOrgaccount(@ModelAttribute ManagerModel managerModel,
                                @RequestParam(value = "id", required = false) String id){
        orgaccountService.modifyOrgaccount(managerModel,Integer.parseInt(id));
        return "redirect:" + Const.CONTROLLER_MANAGE_ORGACCOUNT;

    }
    /**
     * 插入机构业务权限信息
     * @param managerModel
     * @return
     */
    @RequestMapping(value = "insert/orgauth.do" ,method = RequestMethod.POST)
    public Object insertOrgauth(@ModelAttribute ManagerModel managerModel){

        if (orgauthService.insertOrgauth(managerModel)==1) {
            return "redirect:" + Const.CONTROLLER_MANAGE_ORGAUTH;
        }else{
            return "redirect:" + Const.CONTROLLER_MANAGE_ORGAUTH;//先这样写，错误页面需要再做到时候跳转错误提示
        }
    }
    /**
     * 跳转到修改机构业务权限信息
     * @param
     * @return
     **/
    @RequestMapping(value = "modify/orgauth.htm" )
    public ModelAndView modifyOrgAuthDispatch(@RequestParam(value = "id", required = false) String id){
        Map<String, Object> map = new HashMap<String, Object>();
        Orgauth data = orgauthService.getOrgauthById(Integer.parseInt(id));
        map.put("item",data);
        ModelAndView mv = super.modelAndView(map);
        mv.setViewName("manage/modifyorgauth");
        return mv;
    }

    /**
     * 修改机构业务权限信息
     * @param
     * @return
     */
    @RequestMapping(value = "modify/orgauth.do" ,method = RequestMethod.POST)
    public Object modifyOrgauth(@ModelAttribute ManagerModel managerModel,
                                   @RequestParam(value = "id", required = false) String id){
        orgauthService.modifyOrgauth(managerModel,Integer.parseInt(id));
        return "redirect:" + Const.CONTROLLER_MANAGE_ORGAUTH;

    }
    /**
     * 插入机构风险检查表
     * @param managerModel
     * @return
     */
    @RequestMapping(value = "insert/riskcheck.do" ,method = RequestMethod.POST)
    public Object insertRiskcheck(@ModelAttribute ManagerModel managerModel){
        if (riskcheckService.insertRiskcheck(managerModel)==1) {
            return "redirect:" + Const.CONTROLLER_MANAGE_RISKCHECK;
        }else{
            return "redirect:" + Const.CONTROLLER_MANAGE_RISKCHECK;//先这样写，错误页面需要再做到时候跳转错误提示
        }
    }
    /**
     * 跳转到修改机构风险检查表
     * @param
     * @return
     **/
    @RequestMapping(value = "modify/riskcheck.htm" )
    public ModelAndView modifyRiskcheckDispatch(@RequestParam(value = "id", required = false) String id){
        Map<String, Object> map = new HashMap<String, Object>();
        Riskcheck data = riskcheckService.getRiskcheckById(id);
        map.put("item",data);
        ModelAndView mv = super.modelAndView(map);
        mv.setViewName("manage/modifyriskcheck");
        return mv;
    }

    /**
     * 修改机构风险检查表
     * @param
     * @return
     */
    @RequestMapping(value = "modify/riskcheck.do" ,method = RequestMethod.POST)
    public Object modifyRiskcheck(@ModelAttribute ManagerModel managerModel,
                                @RequestParam(value = "id", required = false) String id){
        riskcheckService.modifyRiskcheck(managerModel,id);
        return "redirect:" + Const.CONTROLLER_MANAGE_RISKCHECK;
    }

    /**
     * 插入轧差场次信息表
     * @param managerModel
     * @return
     */
    @RequestMapping(value = "insert/netroundinfo.do" ,method = RequestMethod.POST)
    public Object insertNetroundinfo(@ModelAttribute ManagerModel managerModel){
        if (netroundinfoService.insertNetroundinfo(managerModel)==1) {
            return "redirect:" + Const.CONTROLLER_MANAGE_NETROUNDINFO;
        }else{
            return "redirect:" + Const.CONTROLLER_MANAGE_NETROUNDINFO;//先这样写，错误页面需要再做到时候跳转错误提示
        }
    }
    /**
     * 跳转到修改轧差场次信息表
     * @param
     * @return
     **/
    @RequestMapping(value = "modify/netroundinfo.htm" )
    public ModelAndView modifyNetroundinfoDispatch(@RequestParam(value = "id", required = false) String id){
        Map<String, Object> map = new HashMap<String, Object>();
        Netroundinfo data = netroundinfoService.getNetroundinfoById(id);
        map.put("item",data);
        ModelAndView mv = super.modelAndView(map);
        mv.setViewName("manage/modifynetroundinfo");
        return mv;
    }

    /**
     * 修改轧差场次信息表
     * @param
     * @return
     */
    @RequestMapping(value = "modify/netroundinfo.do" ,method = RequestMethod.POST)
    public Object modifyNetroundinfo(@ModelAttribute ManagerModel managerModel,
                                  @RequestParam(value = "id", required = false) String id){
        netroundinfoService.modifyNetroundinfo(managerModel,id);
        return "redirect:" + Const.CONTROLLER_MANAGE_NETROUNDINFO;
    }

    /**
     * 插入轧差场次信息表
     * @param managerModel
     * @return
     */
    @RequestMapping(value = "insert/orgroundinfo.do" ,method = RequestMethod.POST)
    public Object insertOrgroundinfo(@ModelAttribute ManagerModel managerModel){
        if (orgroundinfoService.insertOrgroundinfo(managerModel)==1) {
            return "redirect:" + Const.CONTROLLER_MANAGE_ORGROUNDINFO;
        }else{
            return "redirect:" + Const.CONTROLLER_MANAGE_ORGROUNDINFO;//先这样写，错误页面需要再做到时候跳转错误提示
        }
    }
    /**
     * 跳转到修改轧差场次信息表
     * @param
     * @return
     **/
    @RequestMapping(value = "modify/orgroundinfo.htm" )
    public ModelAndView modifyOrgroundinfoDispatch(@RequestParam(value = "id", required = false) String id){
        Map<String, Object> map = new HashMap<String, Object>();
        Orgroundinfo data = orgroundinfoService.getOrgroundinfoById(id);
        map.put("item",data);
        ModelAndView mv = super.modelAndView(map);
        mv.setViewName("manage/modifyorgroundinfo");
        return mv;
    }

    /**
     * 修改轧差场次信息表
     * @param
     * @return
     */
    @RequestMapping(value = "modify/orgroundinfo.do" ,method = RequestMethod.POST)
    public Object modifyOrgroundinfo(@ModelAttribute ManagerModel managerModel,
                                     @RequestParam(value = "id", required = false) String id){
        orgroundinfoService.modifyOrgroundinfo(managerModel,id);
        return "redirect:" + Const.CONTROLLER_MANAGE_ORGROUNDINFO;
    }
    /**
     * 插入协议授权信息表
     * @param managerModel
     * @return
     */
    @RequestMapping(value = "insert/consigninfo.do" ,method = RequestMethod.POST)
    public Object insertConsigninfo(@ModelAttribute ManagerModel managerModel){
        if (consigninfoService.insertConsigninfo(managerModel)==1) {
            return "redirect:" + Const.CONTROLLER_MANAGE_CONSIGNINFO;
        }else{
            return "redirect:" + Const.CONTROLLER_MANAGE_CONSIGNINFO;//先这样写，错误页面需要再做到时候跳转错误提示
        }
    }
    /**
     * 跳转到修改协议授权信息表
     * @param
     * @return
     **/
    @RequestMapping(value = "modify/consigninfo.htm" )
    public ModelAndView modifyConsigninfoDispatch(@RequestParam(value = "id", required = false) String id){
        Map<String, Object> map = new HashMap<String, Object>();
        Consigninfo data = consigninfoService.getConsigninfoById(id);
        map.put("item",data);
        ModelAndView mv = super.modelAndView(map);
        mv.setViewName("manage/modifyconsigninfo");
        return mv;
    }

    /**
     * 修改协议授权信息表
     * @param
     * @return
     */
    @RequestMapping(value = "modify/consigninfo.do" ,method = RequestMethod.POST)
    public Object modifyConsigninfo(@ModelAttribute ManagerModel managerModel,
                                     @RequestParam(value = "id", required = false) String id){
        consigninfoService.modifyConsigninfo(managerModel,id);
        return "redirect:" + Const.CONTROLLER_MANAGE_CONSIGNINFO;
    }
    /*****************************************账户绑定信息表*******************************************/
    /**
     * 插入账户绑定信息表
     * @param managerModel
     * @return
     */
    @RequestMapping(value = "insert/acctbindinfo.do" ,method = RequestMethod.POST)
    public Object insertAcctbindinfo(@ModelAttribute ManagerModel managerModel){
        if (acctbindinfoService.insertAcctbindinfo(managerModel)==1) {
            return "redirect:" + Const.CONTROLLER_MANAGE_ACCTBINDINFO;
        }else{
            return "redirect:" + Const.CONTROLLER_MANAGE_ACCTBINDINFO;//先这样写，错误页面需要再做到时候跳转错误提示
        }
    }
    /**
     * 跳转到修改账户绑定信息表
     * @param
     * @return
     **/
    @RequestMapping(value = "modify/acctbindinfo.htm" )
    public ModelAndView modifyAcctbindinfoDispatch(@RequestParam(value = "id", required = false) String id){
        Map<String, Object> map = new HashMap<String, Object>();
        Acctbindinfo data = acctbindinfoService.getAcctbindinfoById(id);
        map.put("item",data);
        map.put("cdtrclasses",CommonOption.getCdtrclassOption());
        map.put("states",CommonOption.getStateOption());
        ModelAndView mv = super.modelAndView(map);
        mv.setViewName("manage/modifyacctbindinfo");
        return mv;
    }

    /**
     * 修改账户绑定信息表
     * @param
     * @return
     */

    @RequestMapping(value = "modify/acctbindinfo.do" ,method = RequestMethod.POST)
    public Object modifyAcctbindinfo(@ModelAttribute ManagerModel managerModel,
                                    @RequestParam(value = "id", required = false) String id){
        acctbindinfoService.modifyAcctbindinfo(managerModel,id);
        return "redirect:" + Const.CONTROLLER_MANAGE_ACCTBINDINFO;
    }

    @ResponseBody
    @RequestMapping(value = "select/orginfo.do")
    public Object selectOrfginfo(@RequestParam(value = "q",required = false) String name){

        return orginfoService.selectOrginfoName(name);
    }

    /**
     * 取得机构号和机构名称
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "select/orgIdAndName.do")
    public Object selectOrgidAndName(@RequestParam(value = "q",required = false) String  name){
        return orginfoService.selectOrgidAndName(name);
    }
    /**
     * 机构信息下载
     * @param managerModel
     * @return
     */
    @RequestMapping(value = "downloadOrginfo.do" , method = { RequestMethod.GET, RequestMethod.POST})
    public ResponseEntity<byte[]> downloadOrginfoTables(@ModelAttribute ManagerModel managerModel, HttpSession session)
            throws Exception{
        String areacode = ((Auth)session.getAttribute(Const.SESSION_USER)).getUser().getAreacode();
        managerModel.setAreacode(areacode);
        List<Orginfo> data = orginfoService.getOrginfo(managerModel);
        HttpHeaders headers = new HttpHeaders();
        String file = DateUtil.formate(new Date(), "FULL");
        String fileName = new String((file + ".csv").getBytes("UTF-8"), "iso-8859-1");//为了解决中文名称乱码问题
        headers.setContentDispositionFormData("attachment", fileName);
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        return new ResponseEntity<byte[]>(CsvWriter.print(data), headers, HttpStatus.CREATED);

    }
    /**
     * 入网机构账户信息下载
     * @param managerModel
     * @return
     */
    @RequestMapping(value = "downloadOrgaccount.do" , method = { RequestMethod.GET, RequestMethod.POST})
    public ResponseEntity<byte[]> downloadOrgaccountTables(@ModelAttribute ManagerModel managerModel, HttpSession session)
            throws Exception{
        String areacode = ((Auth)session.getAttribute(Const.SESSION_USER)).getUser().getAreacode();
        managerModel.setOrgcodelist(orginfoService.getOrgcodeByAreacode(areacode));
        managerModel.setAreacode(areacode);
        List<Orgaccount> data = orgaccountService.getOrgaccount(managerModel);
        HttpHeaders headers = new HttpHeaders();
        String file = DateUtil.formate(new Date(), "FULL");
        String fileName = new String((file + ".csv").getBytes("UTF-8"), "iso-8859-1");//为了解决中文名称乱码问题
        headers.setContentDispositionFormData("attachment", fileName);
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        return new ResponseEntity<byte[]>(CsvWriter.print(data), headers, HttpStatus.CREATED);

    }
    /**
     * 机构业务权限限制表下载
     * @param managerModel
     * @return
     */
    @RequestMapping(value = "downloadOrgauth.do" , method = { RequestMethod.GET, RequestMethod.POST})
    public ResponseEntity<byte[]> downloadOrgauthTables(@ModelAttribute ManagerModel managerModel, HttpSession session)
            throws Exception{
        String areacode = ((Auth)session.getAttribute(Const.SESSION_USER)).getUser().getAreacode();
        managerModel.setOrgcodelist(orginfoService.getOrgcodeByAreacode(areacode));
        managerModel.setAreacode(areacode);
        List<Orgauth> data = orgauthService.getOrgauth(managerModel);
        HttpHeaders headers = new HttpHeaders();
        String file = DateUtil.formate(new Date(), "FULL");
        String fileName = new String((file + ".csv").getBytes("UTF-8"), "iso-8859-1");//为了解决中文名称乱码问题
        headers.setContentDispositionFormData("attachment", fileName);
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        return new ResponseEntity<byte[]>(CsvWriter.print(data), headers, HttpStatus.CREATED);

    }

    /**
     * 机构风险检查表下载
     * @param managerModel
     * @return
     */
    @RequestMapping(value = "downloadRiskcheck.do" , method = { RequestMethod.GET, RequestMethod.POST})
    public ResponseEntity<byte[]> downloadRiskcheckTables(@ModelAttribute ManagerModel managerModel, HttpSession session)
            throws Exception{
        String areacode = ((Auth)session.getAttribute(Const.SESSION_USER)).getUser().getAreacode();
        managerModel.setOrgcodelist(orginfoService.getOrgcodeByAreacode(areacode));
        managerModel.setAreacode(areacode);
        List<Riskcheck> data = riskcheckService.getRiskcheck(managerModel);
        HttpHeaders headers = new HttpHeaders();
        String file = DateUtil.formate(new Date(), "FULL");
        String fileName = new String((file + ".csv").getBytes("UTF-8"), "iso-8859-1");//为了解决中文名称乱码问题
        headers.setContentDispositionFormData("attachment", fileName);
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        return new ResponseEntity<byte[]>(CsvWriter.print(data), headers, HttpStatus.CREATED);

    }
    /**
     * 轧差场次信息表下载
     * @param managerModel
     * @return
     */
    @RequestMapping(value = "downloadNetroundinfo.do" , method = { RequestMethod.GET, RequestMethod.POST})
    public ResponseEntity<byte[]> downloadNetroundinfoTables(@ModelAttribute ManagerModel managerModel, HttpSession session)
            throws Exception{
        List<Netroundinfo> data = netroundinfoService.getNetroundinfo(managerModel);
        HttpHeaders headers = new HttpHeaders();
        String file = DateUtil.formate(new Date(), "FULL");
        String fileName = new String((file + ".csv").getBytes("UTF-8"), "iso-8859-1");//为了解决中文名称乱码问题
        headers.setContentDispositionFormData("attachment", fileName);
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        return new ResponseEntity<byte[]>(CsvWriter.print(data), headers, HttpStatus.CREATED);

    }
    /**
     * 机构轧差场次信息下载
     * @param managerModel
     * @return
     */
    @RequestMapping(value = "downloadOrgroundinfo.do" , method = { RequestMethod.GET, RequestMethod.POST})
    public ResponseEntity<byte[]> downloadOrgroundinfoTables(@ModelAttribute ManagerModel managerModel, HttpSession session)
            throws Exception{
        String areacode = ((Auth)session.getAttribute(Const.SESSION_USER)).getUser().getAreacode();
        managerModel.setOrgcodelist(orginfoService.getOrgcodeByAreacode(areacode));
        managerModel.setAreacode(areacode);
        List<Orgroundinfo> data = orgroundinfoService.getOrgroundinfo(managerModel);
        HttpHeaders headers = new HttpHeaders();
        String file = DateUtil.formate(new Date(), "FULL");
        String fileName = new String((file + ".csv").getBytes("UTF-8"), "iso-8859-1");//为了解决中文名称乱码问题
        headers.setContentDispositionFormData("attachment", fileName);
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        return new ResponseEntity<byte[]>(CsvWriter.print(data), headers, HttpStatus.CREATED);

    }
    /**
     * 协议授权信息表下载
     * @param managerModel
     * @return
     */
    @RequestMapping(value = "downloadConsiginfo.do" , method = { RequestMethod.GET, RequestMethod.POST})
    public ResponseEntity<byte[]> downloadConsigninfoTables(@ModelAttribute ManagerModel managerModel, HttpSession session)
            throws Exception{
        String areacode = ((Auth)session.getAttribute(Const.SESSION_USER)).getUser().getAreacode();
        managerModel.setOrgcodelist(orginfoService.getOrgcodeByAreacode(areacode));
        managerModel.setAreacode(areacode);
        List<Consigninfo> data = consigninfoService.getConsigninfo(managerModel);
        HttpHeaders headers = new HttpHeaders();
        String file = DateUtil.formate(new Date(), "FULL");
        String fileName = new String((file + ".csv").getBytes("UTF-8"), "iso-8859-1");//为了解决中文名称乱码问题
        headers.setContentDispositionFormData("attachment", fileName);
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        return new ResponseEntity<byte[]>(CsvWriter.print(data), headers, HttpStatus.CREATED);

    }
    /**
     * 账户绑定信息表下载
     * @param managerModel
     * @return
     */
    @RequestMapping(value = "downloadAcctbindinfo.do" , method = { RequestMethod.GET, RequestMethod.POST})
    public ResponseEntity<byte[]> downloadAcctbindinfoTables(@ModelAttribute ManagerModel managerModel, HttpSession session)
            throws Exception{
        String areacode = ((Auth)session.getAttribute(Const.SESSION_USER)).getUser().getAreacode();
        managerModel.setOrgcodelist(orginfoService.getOrgcodeByAreacode(areacode));
        managerModel.setAreacode(areacode);
        List<Acctbindinfo> data = acctbindinfoService.getAcctbindinfo(managerModel);
        HttpHeaders headers = new HttpHeaders();
        String file = DateUtil.formate(new Date(), "FULL");
        String fileName = new String((file + ".csv").getBytes("UTF-8"), "iso-8859-1");//为了解决中文名称乱码问题
        headers.setContentDispositionFormData("attachment", fileName);
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        return new ResponseEntity<byte[]>(CsvWriter.print(data), headers, HttpStatus.CREATED);

    }
    /**
     * 处理批量导入文件
     * @param file
     * @param request
     * @return
     */
    @RequestMapping(value = "orginfoImport.do")
    public ModelAndView orginfoImport(@RequestParam(value = "file", required = false) MultipartFile file, HttpServletRequest request){
        String path = request.getSession().getServletContext().getRealPath("upload");
        String fileName = file.getOriginalFilename();
        String fieldsTmp[] = null; // 保存记录中的各个字段
        List<String> result=new ArrayList<String>();
        // 总记录数、成功记录数、失败记录数
        int count = 0, succCount = 0, failCount = 0;
        System.out.println(path);
        File targetFile = new File(path, fileName);
        if(!targetFile.exists()){
            //查看目录是否存在，如何不存在就创建这个目录
            targetFile.mkdirs();
        }
        result.add("操作失败结果明细信息显示如下(后面显示统计结果):");
        result.add("********************************************");
        InputStream in = null;
        try {
            file.transferTo(targetFile);
            in = new FileInputStream(targetFile);//通过对象多态性，进行实例化
            Import imp = ImportFactory.getImporter("xls", in);
            imp.readLine();
            while ((fieldsTmp = imp.readLine()) != null) {
                ++count;
                if (fieldsTmp.length > 0) {
                    if ((fieldsTmp == null) || (fieldsTmp.length != 24)) {
                        result.add("第" + count + "行==>记录字段数目不对,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[0].toString().trim().equals("") || fieldsTmp[0].trim().length() > 10) {
                        result.add("第" + count + "行==>机构代码为空或者大于10位,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[1].toString().trim().equals("") || fieldsTmp[1].trim().length() > 80) {
                        result.add("第" + count + "行==>机构名称为空或者大于80位,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[2].trim().length() > 4) {
                        result.add("第" + count + "行==>机构所属地区大于1位,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[3].trim().length() > 4|| !StringUtils.isInteger(fieldsTmp[3])) {
                        result.add("第" + count + "行==>机构类型大于4位或者不是整数,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[4].trim().length() > 14) {
                        result.add("第" + count + "行==>清算行号大于14位,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[5].trim().length() > 4) {
                        result.add("第" + count + "行==>通讯节点号大于4位,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[6].trim().length() > 32) {
                        result.add("第" + count + "行==>机构允许的业务类型大于32位,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[7].trim().length() > 4|| !StringUtils.isInteger(fieldsTmp[7])) {
                        result.add("第" + count + "行==>协议类型大于4位或者不是整数,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[8].trim().length() > 4) {
                        result.add("第" + count + "行==>协议前缀大于4位,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[9].trim().length() >  4|| !StringUtils.isInteger(fieldsTmp[9])) {
                        result.add("第" + count + "行==>是否检查协议大于4位或者不是整数,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[10].trim().length() > 4 || !StringUtils.isInteger(fieldsTmp[10])) {
                        result.add("第" + count + "行==>密押类型大于4位或者不为整数,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[11].trim().length() > 10 || !StringUtils.isInteger(fieldsTmp[11]) ) {
                        result.add("第" + count + "行==>密押或证书索引号大于10位或者不是整数,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[12].trim().length() > 256 ) {
                        result.add("第" + count + "行==>证书信息大于256位,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[13].trim().length() > 4 || !StringUtils.isInteger(fieldsTmp[13])) {
                        result.add("第" + count + "行==>机构接入类型大于4位或者不是整数,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[14].trim().length() > 4 || !StringUtils.isInteger(fieldsTmp[14])) {
                        result.add("第" + count + "行==>机构服务类型大于4位或者不是整数,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[15].trim().length() > 15 ) {
                        result.add("第" + count + "行==>机构业务发起主机IP大于15位,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[16].trim().length() > 15 ) {
                        result.add("第" + count + "行==>机构业务接收主机IP或服务名称大于15位,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[17].trim().length() > 10 || !StringUtils.isInteger(fieldsTmp[17]) ) {
                        result.add("第" + count + "行==>接收服务通讯端口大于10位或者不是整数,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[18].trim().length() > 4 || !StringUtils.isInteger(fieldsTmp[18])) {
                        result.add("第" + count + "行==>TCP通讯模式大于4位或者不是整数,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[19].trim().length() > 4 || !StringUtils.isInteger(fieldsTmp[19])) {
                        result.add("第" + count + "行==>机构状态大于4位或者不是整数,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[20].trim().length() > 4 || !StringUtils.isInteger(fieldsTmp[20])) {
                        result.add("第" + count + "行==>日志级别大于4位或者不是整数,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[21].trim().length() > 4 || !StringUtils.isInteger(fieldsTmp[21])) {
                        result.add("第" + count + "行==>下载模式大于4位或者不是整数,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[22].trim().length() > 8 ) {
                        result.add("第" + count + "行==>记录创建日期大于15位,请检查");
                        ++failCount;
                        continue;
                    }
                    else if (fieldsTmp[23].trim().length() > 8 ) {
                        result.add("第" + count + "行==>最后修改日期大于15位,请检查");
                        ++failCount;
                        continue;
                    }else{
                        orginfoService.insertOrginfoinfoByArray(fieldsTmp);
                        ++succCount;
                    }
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            System.out.println("转换文件失败，或文件未找到！"+e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
        }
        result.add("---------------------统计结果如下-----------------------");
        result.add("文本总行数:" + count );
        result.add("成功记录数："+succCount);
        result.add("失败记录数："+failCount);
        result.add("空行数："+(count-succCount-failCount));
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("data",result);
        ModelAndView mv = super.modelAndView(map);
        mv.setViewName("manage/orginfoImportResult");
        return mv;
    }



}
